package com.atguigu.test;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * ClassName: Demo1
 * Package: com.atguigu.test
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-10-06
 * Time: 21:27
 */

public class Demo1 {
    public static void main(String[] args) {
        List<User> list = new ArrayList<>();

        User u1 = new User();
        u1.setNum(new BigDecimal(100));

        User u2 = new User();
        u2.setNum(new BigDecimal(200));

        list.add(u1);
        list.add(u2);

        //实现两个数的相加 使用stream流的方式实现
        BigDecimal result =
                list.stream().map(User::getNum).reduce(BigDecimal::add).get();
        System.out.println(result);

    }
}


class User {
    private BigDecimal num;

    public BigDecimal getNum() {
        return num;
    }

    public void setNum(BigDecimal num) {
        this.num = num;
    }
}